Parse.Cloud.define('recycleRoTask', async (req, res) => {
  try {
    const { ids } = req.params
    const roTasks = await new Parse.Query('RoTask').containedIn('objectId', ids).limit(10000).find()
    const tasks = []
    roTasks.forEach(item => {
      const done = item.get('done')
      if (done === -1 || done===-9) {
        item.set('done', 0)
        tasks.push(item)
      }
    })
    await Parse.Object.saveAll(tasks)
    res.success('ok')
  } catch (err) {
    res.error(err)
  }
})

Parse.Cloud.define('setNotRecycle', async (req, res) => {
  try {
    const { ids } = req.params
    const roTasks = await new Parse.Query('RoTask').containedIn('objectId', ids).limit(10000).find()
    const tasks = []
    roTasks.forEach(item => {
      const done = item.get('done')
      if (done===-9) {
        item.set('done', -8)
        tasks.push(item)
      }
    })
    await Parse.Object.saveAll(tasks)
    res.success('ok')
  } catch (err) {
    res.error(err)
  }
})

